from pysqlcipher3 import dbapi2 as sqlite


class Db():
    ''' 数据库操作 '''

    def __init__(self, db_path, db_file_name):
        self.conn = sqlite.connect(db_path + db_file_name)
        self.c = self.conn.cursor()

    def get_tables(self):
        self.c.execute("SELECT name FROM sqlite_master WHERE type='table'")
        return [i[0] for i in self.c.fetchall()]
        # return [i[0] for i in self.c.fetchall() if "Chat_" in i[0]]

    def exec_sql(self, sql):
        self.c.execute(sql)
        return self.c.fetchall()

    def exec_update_sql(self, sql):
        self.c.execute(sql)
        self.conn.commit()
